package com.lancoo.hanvon.sdk;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapFactory.Options;

import com.hanvon.HWCloudManager;
import com.hanvon.ResultNullError;
import com.hanvon.utils.BitmapUtil;

import org.json.JSONObject;

public class SDK_GeneralTextLanguage {
    public static String GeneralTextDiscern(String isText, String picPath, String androidKey, String whitelist) {
        if (null != picPath && null != androidKey && null != whitelist) {
            String paramData = null;

            try {
                Options options = new Options();
                options.inJustDecodeBounds = true;
                BitmapFactory.decodeFile(picPath, options);
                options.inSampleSize = BitmapUtil.calculateInSampleSize(options, 960, 640);
                options.inJustDecodeBounds = false;
                Bitmap bitmap = BitmapFactory.decodeFile(picPath, options);
                paramData = BitmapUtil.encodeBitmapData(bitmap);
                JSONObject paramJson = new JSONObject();
                paramJson.put("uid", HWCloudManager.UID);
                paramJson.put("isText", isText);
                paramJson.put("image", paramData);
                String url = "http://api.hanvon.com/rt/ws/v1/ocr/generaltext/recg?key=" + androidKey + "&code=" + "9c56015f-af3c-4b82-a4eb-dc34efa54683" + "&whitelist=" + whitelist;
                String result = SDK_HttpClientHelper.postData(url, paramJson.toString());
                return result;
            } catch (Exception var10) {
                var10.printStackTrace();
                return null;
            }
        } else {
            return ResultNullError.getValue();
        }
    }
}
